using UnityEngine;
using System.Collections;

/// <summary>
/// Drag gesture: a full finger press > move > release sequence
/// </summary>
[AddComponentMenu( "FingerGestures/Gesture Recognizers/Drag" )]
public class TwoDragGestureRecognizer  : DragGestureRecognizer
{
	protected override bool CanBegin (FingerGestures.IFingerList touches)
	{
		if( touches.Count < GetRequiredFingerCount() )
			return false;

		// check with the delegate (provided we have one set)
		if( !CheckCanBeginDelegate( touches ) )
			return false;

		return true;
	}
	public int dragEndCount = 1;
	protected override GestureState OnActive (FingerGestures.IFingerList touches)
	{
		if( touches.Count == dragEndCount)
		{
			// fingers were lifted off
			if( touches.Count < RequiredFingerCount )
			{
				RaiseOnDragEnd();
				return GestureState.Failed;
			}

			return GestureState.Failed;
		}

		Position = touches.GetAveragePosition();

		MoveDelta = Position - lastPos;

		if( MoveDelta.sqrMagnitude > 0 )
		{
			RaiseOnDragMove();
			lastPos = Position;
		}

		return GestureState.InProgress;
	}
}
